package approve.action;

import java.net.URLEncoder;

import nguyen.dao.ReceiverDocumentDAO;
import model.pojo.Document;
import model.pojo.Employee;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.TextView;

public class Re_ViewForm_LessThan10 extends Activity{
	//component
	TextView la_title,la_content;
	EditText title;
	TextView la_createDate,la_writer,re_createDate;
	EditText re_employee;
	WebView content;
	
	//bundle
	Document doc=null;	
	String database = "admin";	
	String lang = "EN";
	Bundle language=null;
	Employee emp=null;	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.re_viewform_lessthan10);
		getComponent();
		
		loadBundle();
		loadLanguage();
		
		viewDocument();
		
	}
	
	private void getComponent(){
		la_createDate=(TextView) findViewById(R.id.la_createDate);
		la_writer=(TextView) findViewById(R.id.la_writer);
		re_createDate = (TextView) findViewById(R.id.re_createDate);
		re_employee = (EditText) findViewById(R.id.re_employee);
		
		la_title=(TextView) findViewById(R.id.la_title);
		la_content=(TextView) findViewById(R.id.la_content);
		
		title=(EditText) findViewById(R.id.title);
		content=(WebView) findViewById(R.id.content);
	}
	
	private void loadBundle(){
		Bundle extras= getIntent().getExtras();
		if(extras!=null){
			database=extras.getString("database");
			lang=extras.getString("lang");
			emp=(Employee) extras.get("em");
			doc=(Document) extras.get("doc");	
			language=extras.getBundle(lang);
		}
	}
	private void loadLanguage(){
		if(language!=null){
			la_createDate.setText(language.getString("created-date")+": ");
			la_writer.setText(language.getString("writer")+"/"+language.getString("Department"));
			
			la_title.setText(language.getString("title"));
			la_content.setText(language.getString("content"));
		}
	}
	


	private void viewDocument(){
		if(doc!=null){
			re_createDate.setText(doc.getTimecreate()+"");
			re_employee.setText(doc.getEmployeeName()+"/"+doc.getDepartment());
			
			title.setText(doc.getTitle());
			
			content.getSettings().setLoadWithOverviewMode(true);
			content.getSettings().setUseWideViewPort(true);
			final String mimeType = "text/html";
			String header = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
			String str=header+doc.getContent();
			content.loadData(URLEncoder.encode(str).replaceAll("\\+"," "), mimeType, null);
		}
	}
}
